﻿using System.Threading.Tasks;
using System.Linq;

namespace Sidvall.IdentityManager.Data.IO.Model.StorageManagers
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public static partial class AspNetRolesManager
    {
        #region Public Members

        #region DeleteItemsAsync

        static partial void OnBeforeDeleteItems(string path, global::Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext);
        static partial void OnAfterDeleteItems(string path, global::Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext);
        static partial void OnDeleteItem(string filePath, global::Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext, global::Sidvall.IdentityManager.Data.IO.Entities.AspNetRoles item, ref bool deleteItem);
        public static async Task DeleteItemsAsync(string path, global::Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");
            OnBeforeDeleteItems(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
            {
                var filePath = await GetPathAsync(path, dataPortalContext.OperationContext.Filter).ConfigureAwait(false);
                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    var item = await LoadItemAsync(filePath).ConfigureAwait(false);
                    var deleteItem = true;
                    OnDeleteItem(filePath, dataPortalContext, item, ref deleteItem);
                    if (deleteItem)
                    {
                        await Sidvall.SystemContext.Current.SystemStorageManager.DeleteFileAsync(filePath).ConfigureAwait(false);
                        dataPortalContext.ResultValueItem += 1;
                    }
                }
                else
                {
                    var folderPath = await GetPathAsync(path, string.Empty).ConfigureAwait(false);
                    var fileNames = await Sidvall.SystemContext.Current.SystemStorageManager.GetFileNamesAsync(folderPath, null, Sidvall.IO.SearchOption.TopDirectoryOnly).ConfigureAwait(false);
                    foreach (var fileName in fileNames)
                    {
                        var item = await LoadItemAsync(fileName).ConfigureAwait(false);
                        var deleteItem = (item == null);
                        OnDeleteItem(fileName, dataPortalContext, item, ref deleteItem);
                        if (deleteItem)
                        {
                            await Sidvall.SystemContext.Current.SystemStorageManager.DeleteFileAsync(fileName).ConfigureAwait(false);
                            dataPortalContext.ResultValueItem += 1;
                        }
                    }
                }
            }
            OnAfterDeleteItems(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
        }

        #endregion
        #region NewItemAsync

        static partial void OnBeforeNewItem(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        public static async Task NewItemAsync(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.CreateCriteria> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");
            OnBeforeNewItem(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                dataPortalContext.ResultValueItem = new global::Sidvall.IdentityManager.Data.IO.Entities.AspNetRoles();
        }

        #endregion
        #region NewItemsAsync

        static partial void OnBeforeNewItems(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        public static async Task NewItemsAsync(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.CreateCriteria> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");
            OnBeforeNewItems(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                dataPortalContext.ResultValueListProvider = new global::Sidvall.IdentityManager.Data.IO.Entities.AspNetRolesCollectionItem();
        }

        #endregion
        #region GetItemAsync

        static partial void OnBeforeGetItem(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.FetchCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField, global::Sidvall.IdentityManager.Data.Relations.AspNetRolesRelation>> dataPortalContext);
        static partial void OnAfterGetItem(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.FetchCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField, global::Sidvall.IdentityManager.Data.Relations.AspNetRolesRelation>> dataPortalContext);
        static partial void OnGetItem(string filePath, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.FetchCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField, global::Sidvall.IdentityManager.Data.Relations.AspNetRolesRelation>> dataPortalContext, global::Sidvall.IdentityManager.Data.IO.Entities.AspNetRoles item, ref bool returnItem);
        public static async Task GetItemAsync(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.FetchCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField, global::Sidvall.IdentityManager.Data.Relations.AspNetRolesRelation>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");
            OnBeforeGetItem(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
            {
                var filePath = await GetPathAsync(path, dataPortalContext.OperationContext.Filter).ConfigureAwait(false);
                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    var item = await LoadItemAsync(filePath).ConfigureAwait(false);
                    var returnItem = true;
                    OnGetItem(filePath, dataPortalContext, item, ref returnItem);
                    if (returnItem)
                        dataPortalContext.ResultValueItem = item;
                }
                else
                {
                    var folderPath = await GetPathAsync(path, string.Empty).ConfigureAwait(false);
                    var fileNames = await Sidvall.SystemContext.Current.SystemStorageManager.GetFileNamesAsync(folderPath, null, Sidvall.IO.SearchOption.TopDirectoryOnly).ConfigureAwait(false);
                    foreach (var fileName in fileNames)
                    {
                        var item = await LoadItemAsync(fileName).ConfigureAwait(false);
                        if (item == null)
                            continue;
                        var returnItem = false;
                        OnGetItem(fileName, dataPortalContext, item, ref returnItem);
                        if (returnItem)
                        {
                            dataPortalContext.ResultValueItem = item;
                            break;
                        }
                    }
                }
            }
            OnAfterGetItem(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
        }

        #endregion
        #region GetItemsAsync

        static partial void OnBeforeGetItems(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.FetchListCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField, global::Sidvall.IdentityManager.Data.Relations.AspNetRolesRelation>> dataPortalContext);
        static partial void OnAfterGetItems(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.FetchListCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField, global::Sidvall.IdentityManager.Data.Relations.AspNetRolesRelation>> dataPortalContext);
        static partial void OnGetItems(string filePath, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.FetchListCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField, global::Sidvall.IdentityManager.Data.Relations.AspNetRolesRelation>> dataPortalContext, global::Sidvall.IdentityManager.Data.IO.Entities.AspNetRoles item, ref bool returnItem);
        public static async Task GetItemsAsync(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, global::Sidvall.Data.FetchListCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField, global::Sidvall.IdentityManager.Data.Relations.AspNetRolesRelation>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");
            OnBeforeGetItems(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
            {
                var folderPath = await GetPathAsync(path, string.Empty).ConfigureAwait(false);
                var fileNames = await Sidvall.SystemContext.Current.SystemStorageManager.GetFileNamesAsync(folderPath, null, Sidvall.IO.SearchOption.TopDirectoryOnly).ConfigureAwait(false);
                var items = new global::Sidvall.IdentityManager.Data.IO.Entities.AspNetRolesCollectionItem();
                foreach (var fileName in fileNames)
                {
                    var item = await LoadItemAsync(fileName).ConfigureAwait(false);
                    if (item == null)
                        continue;
                    var returnItem = true;
                    OnGetItems(fileName, dataPortalContext, item, ref returnItem);
                    if (returnItem)
                        items.Add(item);
                }
                dataPortalContext.ResultValueListProvider = items;
            }
            OnAfterGetItems(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
        }

        #endregion
        #region GetItemCountAsync

        static partial void OnBeforeGetItemCount(string path, global::Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext);
        static partial void OnAfterGetItemCount(string path, global::Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext);
        public static async Task GetItemCountAsync(string path, global::Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");

            OnBeforeGetItemCount(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
            {
                var folderPath = await GetPathAsync(path, string.Empty).ConfigureAwait(false);
                var fileNames = await Sidvall.SystemContext.Current.SystemStorageManager.GetFileNamesAsync(folderPath, null, Sidvall.IO.SearchOption.TopDirectoryOnly).ConfigureAwait(false);
                dataPortalContext.ResultValueItem = fileNames.Count();
            }
            OnAfterGetItemCount(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
        }

        #endregion
        #region SaveItemAsync

        static partial void OnBeforeSaveItem(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, Sidvall.Data.SaveContext<global::Sidvall.IdentityManager.Data.IAspNetRoles>> dataPortalContext);
        static partial void OnAfterSaveItem(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, Sidvall.Data.SaveContext<global::Sidvall.IdentityManager.Data.IAspNetRoles>> dataPortalContext);
        public static async Task SaveItemAsync(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, Sidvall.Data.SaveContext<global::Sidvall.IdentityManager.Data.IAspNetRoles>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");
            OnBeforeSaveItem(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
            {
                await SaveItemAsync(path, dataPortalContext.OperationContext.Item, dataPortalContext.OperationContext.Settings).ConfigureAwait(false);
                dataPortalContext.ResultValueItem = dataPortalContext.OperationContext.Item;
                dataPortalContext.ResultValueIsNewObject = false;
            }
            OnAfterSaveItem(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
        }

        #endregion
        #region SaveItemsAsync

        static partial void OnBeforeSaveItems(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.IdentityManager.Data.IAspNetRoles>>> dataPortalContext);
        static partial void OnAfterSaveItems(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.IdentityManager.Data.IAspNetRoles>>> dataPortalContext);
        public static async Task SaveItemsAsync(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.IdentityManager.Data.IAspNetRoles, Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.IdentityManager.Data.IAspNetRoles>>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");
            OnBeforeSaveItems(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
            {
                await SaveItemsAsync(path, dataPortalContext.OperationContext.Item.DataItems, dataPortalContext.OperationContext.Settings).ConfigureAwait(false);
                dataPortalContext.ResultValueListProvider = dataPortalContext.OperationContext.Item;
                dataPortalContext.ResultValueIsNewObject = false;
            }
            OnAfterSaveItems(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
        }

        #endregion
        #region UpdateItemAsync

        static partial void OnBeforeUpdateItem(string path, global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemContext<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext);
        static partial void OnAfterUpdateItem(string path, global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemContext<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext);
        public static async Task UpdateItemAsync(string path, global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemContext<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");
            OnBeforeUpdateItem(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
            {
                await UpdateItemAsync(path, dataPortalContext.OperationContext.DataRowItem).ConfigureAwait(false);
                dataPortalContext.ResultValueItem = 1;
            }
            OnAfterUpdateItem(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
        }

        #endregion
        #region UpdateItemsAsync

        static partial void OnBeforeUpdateItems(string path, global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemsContext<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext);
        static partial void OnAfterUpdateItems(string path, global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemsContext<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext);
        public static async Task UpdateItemsAsync(string path, global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemsContext<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException("dataPortalContext");
            OnBeforeUpdateItems(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
            if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
            {
                await UpdateItemsAsync(path, dataPortalContext.OperationContext.DataRowItems).ConfigureAwait(false);
                dataPortalContext.ResultValueItem = 1;
            }
            OnAfterUpdateItems(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
        }

        #endregion
        #region ExecuteAsync

        static partial void OnExecute(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.Data.CommandCriteria, global::Sidvall.Data.CommandCriteria> dataPortalContext);
        public static async Task ExecuteAsync(string path, global::Sidvall.Business.DataPortalContext<global::Sidvall.Data.CommandCriteria, global::Sidvall.Data.CommandCriteria> dataPortalContext)
        {
            OnExecute(path, dataPortalContext);
            await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
        }

        #endregion

        #endregion
        #region Private Members

        #region GetKey

        static partial void OnGetKey(global::Sidvall.IdentityManager.Data.IAspNetRoles item, ref string key);
        internal static string GetKey(global::Sidvall.IdentityManager.Data.IAspNetRoles item)
        {
            var key = string.Empty;
            OnGetKey(item, ref key);
            if (!string.IsNullOrWhiteSpace(key))
                return key;
            return Sidvall.IdentityManager.Data.IO.SystemContext.Current.EntityFacade.AspNetRolesManager.GetKey(item);
        }
        static partial void OnGetKey(global::Sidvall.Data.Filter<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField> item, ref string key);
        internal static string GetKey(global::Sidvall.Data.Filter<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField> item)
        {
            var key = string.Empty;
            OnGetKey(item, ref key);
            if (!string.IsNullOrWhiteSpace(key))
                return key;
            return Sidvall.IdentityManager.Data.IO.SystemContext.Current.EntityFacade.AspNetRolesManager.GetKey(item);
        }

        #endregion
        #region GetPathAsync

        static partial void OnGetPath(global::Sidvall.IdentityManager.Data.IAspNetRoles item, ref string filePath);
        internal static async Task<string> GetPathAsync(string path, global::Sidvall.IdentityManager.Data.IAspNetRoles item)
        {
            var filePath = string.Empty;
            OnGetPath(item, ref filePath);
            if (!string.IsNullOrWhiteSpace(filePath))
                return filePath;
            var key = GetKey(item);
            if (!string.IsNullOrWhiteSpace(key))
                return await GetPathAsync(path, key).ConfigureAwait(false);
            return null;
        }
        static partial void OnGetPath(global::Sidvall.Data.Filter<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField> item, ref string filePath);
        internal static async Task<string> GetPathAsync(string path, global::Sidvall.Data.Filter<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField> item)
        {
            var filePath = string.Empty;
            OnGetPath(item, ref filePath);
            if (!string.IsNullOrWhiteSpace(filePath))
                return filePath;
            var key = GetKey(item);
            if (!string.IsNullOrWhiteSpace(key))
                return await GetPathAsync(path, key).ConfigureAwait(false);
            return null;
        }
        internal static async Task<string> GetPathAsync(string path, string key)
        {
            path = System.IO.Path.Combine(path, "AspNetRoles");
            if (!await Sidvall.SystemContext.Current.SystemStorageManager.FolderExistsAsync(path).ConfigureAwait(false))
                await Sidvall.SystemContext.Current.SystemStorageManager.CreateFolderAsync(path).ConfigureAwait(false);
            if (string.IsNullOrWhiteSpace(key))
                return path;
            else
                return System.IO.Path.Combine(path, key + ".json");
        }

        #endregion
        #region LoadItemAsync

        internal static async Task<global::Sidvall.IdentityManager.Data.IO.Entities.AspNetRoles> LoadItemAsync(string filePath)
        {
            string content;

            if (await Sidvall.SystemContext.Current.SystemStorageManager.FileExistsAsync(filePath).ConfigureAwait(false))
                content = await Sidvall.SystemContext.Current.SystemStorageManager.ReadAllTextAsync(filePath).ConfigureAwait(false);
            else
                content = null;
            if (string.IsNullOrWhiteSpace(content))
                return null;
            return Sidvall.Serialization.SerializerManager.Current.Deserialize<global::Sidvall.IdentityManager.Data.IO.Entities.AspNetRoles>(content);
        }

        #endregion
        #region SaveItemAsync

        static partial void OnBeforeSaveItem(string filePath, global::Sidvall.IdentityManager.Data.IAspNetRoles item, Sidvall.Data.SaveSettings settings);
        internal static async Task SaveItemAsync(string path, global::Sidvall.IdentityManager.Data.IAspNetRoles item, Sidvall.Data.SaveSettings settings)
        {
            var rowState = Sidvall.Data.SaveSettings.GetDataRowState(settings, item);
            switch (rowState)
            {
                case Sidvall.Data.DataRowState.Added:
                    item.Id = (string)await GetNextIdAsync(global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField.Id).ConfigureAwait(false);
                    break;
                default:
                    break;
            }
            var filePath = await GetPathAsync(path, item).ConfigureAwait(false);
            if (!string.IsNullOrWhiteSpace(filePath))
            {
                OnBeforeSaveItem(filePath, item, settings);
                Sidvall.IdentityManager.Data.IO.SystemContext.Current.EntityFacade.AspNetRolesManager.AcceptChanges(item);
                var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(item);
                await Sidvall.SystemContext.Current.SystemStorageManager.WriteAllTextAsync(filePath, content).ConfigureAwait(false);
            }
        }

        #endregion
        #region SaveItemsAsync

        internal static async Task SaveItemsAsync(string path, System.Collections.Generic.IEnumerable<global::Sidvall.IdentityManager.Data.IAspNetRoles> items, Sidvall.Data.SaveSettings settings)
        {
            foreach (var item in items)
                await SaveItemAsync(path, item, settings).ConfigureAwait(false);
        }

        #endregion
        #region UpdateItemsAsync

        internal static async Task UpdateItemsAsync(string path, System.Collections.Generic.IEnumerable<Sidvall.Data.DataRowItem<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField>> dataRowItems)
        {
            foreach (var dataRowItem in dataRowItems)
                await UpdateItemAsync(path, dataRowItem).ConfigureAwait(false);
        }

        #endregion
        #region UpdateItemAsync

        static partial void OnBeforeUpdateItem(string filePath, global::Sidvall.IdentityManager.Data.IAspNetRoles item, Sidvall.Data.DataRowItem<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField> dataRowItem);
        internal static async Task UpdateItemAsync(string path, Sidvall.Data.DataRowItem<global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField> dataRowItem)
        {
            var filePath = await GetPathAsync(path, dataRowItem.Key).ConfigureAwait(false);
            if (!string.IsNullOrWhiteSpace(filePath))
            {
                var item = await LoadItemAsync(filePath).ConfigureAwait(false);
                if (item == null)
                    return;
                foreach (var fieldValueItem in dataRowItem.FieldValueItems)
                {
                    global::Sidvall.IdentityManager.Data.IO.SystemContext.Current.EntityFacade.AspNetRolesManager.LoadInstanceField(item, fieldValueItem.FieldName,
                        fieldValueItem.GetFieldValue(), false, false, false);
                }
                OnBeforeUpdateItem(filePath, item, dataRowItem);
                Sidvall.IdentityManager.Data.IO.SystemContext.Current.EntityFacade.AspNetRolesManager.AcceptChanges(item);
                var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(item);
                await Sidvall.SystemContext.Current.SystemStorageManager.WriteAllTextAsync(filePath, content).ConfigureAwait(false);
            }
        }

        #endregion
        #region GetNextIdAsync

        internal static async Task<object> GetNextIdAsync(global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField fieldId)
        {
            object id;

            switch (fieldId)
            {
                case global::Sidvall.IdentityManager.Data.Fields.AspNetRolesField.Id:
                    id = await Task.FromResult(System.Guid.NewGuid().ToString()).ConfigureAwait(false);
                    return id;
                default:
                    return null;
            }
        }

        #endregion

        #endregion
    }
}